package net.lab1024.sa.admin.module.business.marker.service;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import net.lab1024.sa.admin.module.business.marker.dao.MarkerDao;
import net.lab1024.sa.admin.module.business.marker.domain.entity.MarkerEntity;
import net.lab1024.sa.admin.module.business.marker.domain.form.MarkerAddForm;
import net.lab1024.sa.admin.module.business.marker.domain.form.MarkerQueryForm;
import net.lab1024.sa.admin.module.business.marker.domain.form.MarkerUpdateForm;
import net.lab1024.sa.admin.module.business.marker.domain.vo.MarkerVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;

/**
 * 图标地点 Service
 *
 * @Author 骆伟林
 * @Date 2025-10-27 11:46:41
 * @Copyright 软件需求工程第八组
 */

@Service
public class MarkerService {

    @Resource
    private MarkerDao markerDao;

    /**
     * 分页查询
     */
    public PageResult<MarkerVO> queryPage(MarkerQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<MarkerVO> list = markerDao.queryPage(page, queryForm);
        return SmartPageUtil.convert2PageResult(page, list);
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(MarkerAddForm addForm) {
        MarkerEntity markerEntity = SmartBeanUtil.copy(addForm, MarkerEntity.class);
        markerDao.insert(markerEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     */
    public ResponseDTO<String> update(MarkerUpdateForm updateForm) {
        MarkerEntity markerEntity = SmartBeanUtil.copy(updateForm, MarkerEntity.class);
        markerDao.updateById(markerEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     */
    public ResponseDTO<String> batchDelete(List<Long> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        markerDao.batchUpdateDeleted(idList, true);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(String markerId) {
        if (null == markerId){
            return ResponseDTO.ok();
        }

        markerDao.updateDeleted(markerId, true);
        return ResponseDTO.ok();
    }

    /**
     * 根据图表地点id获取图标地点列表
     */
    public List<MarkerVO> getMarkerListByAddressId(Long addressId) {
        return SmartBeanUtil.copyList(
                markerDao.selectList(new LambdaQueryWrapper<MarkerEntity>()
                        .eq(MarkerEntity::getAddressId, addressId)
                        .eq(MarkerEntity::getDeletedFlag, false)),
                MarkerVO.class);

    }


}
